package cn.quevo.ez2.token;

import cn.quevo.core.lang.StringUtils;
import cn.quevo.ucenter.client.entity.TokenClientUser;
import cn.quevo.ucenter.client.entity.TreeMenu;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zqiang 17600171259@163.com
 * @description
 * @date created at $time$ $date$
 */
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class TokenClientUserDto extends TokenClientUser implements Serializable {
    /** 公司 logo路径 */
    private String logo;
    /** 公司id*/
    private Long compId;
    /** 角色字符串集合 */
    private String roles;
    /** 权限字符串集合 */
    private String permissions;
    /** 访问令牌 */
    private String accessToken;
    /** 客户端ID */
    private String clientId;
    /** 主体ID */
    private Long subjectId;
    /** 过期时间 */
    private Long expiredIn;
    /** 记录拥有者 */
    private Long recordOwnerId;
    /** 菜单列表 */
    private List<TreeMenu> menus;
    /** 记录拥有者名称 */
    private String recordOwnerName;
    /** 昵称 */
    private String nickName;
    /** 用户名 */
    private String userName;

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public Long getCompId() {
        return compId;
    }

    public void setCompId(Long compId) {
        this.compId = compId;
    }

    @Override
    public void setRoles(String roles) {
        this.roles = roles;
    }

    @Override
    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }

    @Override
    public String getAccessToken() {
        return this.accessToken;
    }

    @Override
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    @Override
    public String getClientId() {
        return this.clientId;
    }

    @Override
    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    @Override
    public Long getSubjectId() {
        return subjectId;
    }

    @Override
    public void setSubjectId(Long subjectId) {
        this.subjectId = subjectId;
    }

    @Override
    public Long getExpiredIn() {
        this.expiredIn = 7200L;
        return this.expiredIn;
    }

    @Override
    public void setExpiredIn(Long expiredIn) {
        this.expiredIn = expiredIn;
    }

    @Override
    public Long getRecordOwnerId() {
        return recordOwnerId;
    }

    @Override
    public void setRecordOwnerId(Long recordOwnerId) {
        this.recordOwnerId = recordOwnerId;
    }

    @Override
    public List<TreeMenu> getMenus() {
        return menus;
    }

    @Override
    public void setMenus(List<TreeMenu> menus) {
        this.menus = menus;
    }

    @Override
    public String getRecordOwnerName() {
        return recordOwnerName;
    }

    @Override
    public void setRecordOwnerName(String recordOwnerName) {
        this.recordOwnerName = recordOwnerName;
    }

    @Override
    public String getNickName() {
        return nickName;
    }

    @Override
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    @Override
    public String getUserName() {
        return userName;
    }

    @Override
    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public boolean isExpired() {
        return super.isExpired();
    }

    @Override
    public Set<String> getRoles() {
        return this.convertStringToSet(roles);
    }

    @Override
    public Set<String> getPermissions() {
        return this.convertStringToSet(permissions);
    }

    /**
     * 字符串转换成Set
     *
     * @author July july_sky@foxmail.com
     * @date 2017年12月29日 下午10:26:16
     * @param strs
     * @return
     */
    protected Set<String> convertStringToSet(String strs) {
        if(StringUtils.isBlank(strs)) {
            return new HashSet<>();
        }
        String[] args = strs.split(",");
        Set<String> set = new HashSet<>(args.length);
        set.addAll(Arrays.asList(args));
        return set;
    }
}
